package com.common.shared.usermanager;

import java.util.ArrayList;
import java.util.Set;

import com.google.gwt.user.client.rpc.IsSerializable;

public class TransfarableUser implements IsSerializable {

	/**
	 * 
	 */
	private int user_id;
	private String username;
	private int subregionid;
	private int regionid;
	private ArrayList<Integer> permitionIds;
	private ArrayList<String> permitionNames;

	private ArrayList<Integer> groupIds;
	private ArrayList<String> groupNames;

	public int getUser_id() {
		return user_id;
	}

	public void setUser_id(int user_id) {
		this.user_id = user_id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public ArrayList<Integer> getPermitionIds() {
		if (permitionIds == null)
			permitionIds = new ArrayList<Integer>();
		return permitionIds;
	}

	public void setPermitionIds(ArrayList<Integer> permitionIds) {
		this.permitionIds = permitionIds;
	}

	public ArrayList<String> getPermitionNames() {
		if (permitionNames == null)
			permitionNames = new ArrayList<String>();
		return permitionNames;
	}

	public void setPermitionNames(ArrayList<String> permitionNames) {
		this.permitionNames = permitionNames;
	}

	public ArrayList<Integer> getGroupIds() {
		if (groupIds == null)
			groupIds = new ArrayList<Integer>();
		return groupIds;
	}

	public void setGroupIds(ArrayList<Integer> groupIds) {
		this.groupIds = groupIds;
	}

	public ArrayList<String> getGroupNames() {
		if (groupNames == null)
			groupNames = new ArrayList<String>();
		return groupNames;
	}

	public void setGroupNames(ArrayList<String> groupNames) {
		this.groupNames = groupNames;
	}

	private ArrayList<Integer> convertSetToArrayInt(Set<Integer> set) {
		ArrayList<Integer> ret = new ArrayList<Integer>();
		for (Integer integer : set) {
			ret.add(integer);
		}
		return ret;
	}

	private ArrayList<String> convertSetToArraySt(Set<String> set) {
		ArrayList<String> ret = new ArrayList<String>();
		for (String str : set) {
			ret.add(str);
		}
		return ret;
	}

	public void generateFromRealUser(SUser user) {
		user_id = user.getUser().getId();
		username = user.getTextVal();
		permitionIds = convertSetToArrayInt(user.permitionIds.keySet());
		permitionNames = convertSetToArraySt(user.permitionNames.keySet());
		groupIds = convertSetToArrayInt(user.groupIds.keySet());
		groupNames = convertSetToArraySt(user.groupNames.keySet());
	}

	public int getSubregionid() {
		return subregionid;
	}

	public void setSubregionid(int subregionid) {
		this.subregionid = subregionid;
	}

	public int getRegionid() {
		return regionid;
	}

	public void setRegionid(int regionid) {
		this.regionid = regionid;
	}

}
